<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>5-03 创建操作区</title>
</head>
<body>
  <canvas id="c" width="300" height="300" style="border: 1px solid #ccc;"></canvas>

  <script>
    const context = document.getElementById('c')
    const ctx = context.getContext('2d')

    const area = ctx.createImageData(150, 150)

    const data = area.data
    for (var i = 0; i < data.length; i += 4) {
      data[i + 0] = 66
      data[i + 1] = 102
      data[i + 2] = 102
      data[i + 3] = 255
    }

    ctx.putImageData(area, 10, 10)
  </script>
</body>
</html>